//
//  ReadViewController.m
//  LO_MUSIC
//
//  Created by 胡林 on 16/2/24.
//  Copyright © 2016年 杨少锋. All rights reserved.
//

#import "ReadViewController.h"
#define GETURL @"http://api2.pianke.me/read/columns"
#define POSTURL @"http://api2.pianke.me/ting/radio"
@interface ReadViewController ()

@end

@implementation ReadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"阅读";
    self.view.backgroundColor = [UIColor cyanColor];
       //POST
    
    [self get];
    
    
    // Do any additional setup after loading the view.
}

-(void)get{
    //GET
    NSURLSession * session = [NSURLSession sharedSession];
    // 把字符串用UTF8编码（主要防止字符串里有汉字）
    
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:GETURL];
    NSString * urlString = [GETURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //被废弃的
    //    NSString * str = GETURL.UTF8String;
    
    
    //设置请求方式
    [request setHTTPMethod:@"GET"];
    //
    [request setHTTPBody:nil];
    
    //请求头：
    NSURLSessionTask * task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
//        NSLog(@"%@",result);
         NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        self.arrayAll= [NSMutableArray array];
        /*for (NSString *key in dic[@"result"]) {
         if ([key isEqualToString:@"data"]) {
         NSMutableArray *arr = dic[@"result"][@"data"];
         for (NSDictionary *d in arr) {
         CinemaModel *model = [[CinemaModel alloc]init];
         [model setValuesForKeysWithDictionary:d];
         [arrayAllData addObject:model];
         }
         }
*/
        for (NSString * key in dict[@"data"]) {
            if ([key isEqualToString:@"list"]) {
                
            }
        }
    }];
    //开启
    [task resume];
    

}
-(void)post{
    //post
    NSURLSession * session = [NSURLSession sharedSession];
    // 把字符串用UTF8编码（主要防止字符串里有汉字）
    
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:POSTURL];
    NSString * urlString = [POSTURL stringByAddingPercentEncodingWithAllowedCharacters:set];
    
    NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    //被废弃的
    //    NSString * str = GETURL.UTF8String;
    
    
    //设置请求方式
    [request setHTTPMethod:@"POST"];
    //设置请求体
    //@{@"client":@"1",@"deviceid":@"63A94D37-33F9-40FF-9EBB-481182338873",@"auth":@"",@"version":@"3.0.2"}
    NSString *bodyStr = @"client=1&deviceid=63A94D37-33F9-40FF-9EBB-481182338873&auth=&version=3.0.2";
    NSData *data = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
    [request setHTTPBody:data];
    
    
    //请求头：
    NSURLSessionTask * task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
        NSLog(@"%@",result);
    }];
    //开启
    [task resume];
    

}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
